<?php 
namespace app\admin\controller;
use think\Request;
use app\common\model\AdminUser;
use app\common\controller\Base;
use app\common\model\AdminGroup;
/**
 * @Author: YeMiao
 * @Date:   2017-07-31 10:37:16
 * @Last Modified by:   YeMiao
 * @Last Modified time: 2017-09-12 09:47:10
 */


class Admin extends Base{
	// 用户列表
	public function index(){
		$user = new AdminUser();
		$list = $user->get_list();
		$this->assign('list',$list);
		return $this->fetch();
	}
	// 用户添加
	public function user_add(){
		if(Request::instance()->isPost()){
			if(input('post.')){
				$user = new AdminUser();
				$add = $user->add_user(input('post.'));
				return $add;
			}else{
				$group = new AdminGroup();
				$list = $group->get_list();
				$this->assign('list',$list);
				return $this->fetch();
			}		
		}
	}
	// 用户修改
	public function user_edit(){
		if(Request::instance()->isPost()){
			$group = new AdminGroup();
			$list = $group->get_list();
			$this->assign('id',input('post.id'));
			$this->assign('list',$list); 
			return $this->fetch();
		}	
	}
	// 用户删除
	public function user_del(){
		if(Request::instance()->isPost()){
			$user = new AdminUser();
			$add = $user->del_user(input('post.'));
			return $add;
		}
	}
	// 用户状态更改
	public function user_state(){
		if(Request::instance()->isPost()){
			$user = new AdminUser();
			$state = $user->update_state_user(input('post.'));
			return $state;
		}	
	}
	// 用户组更变
	public function user_group(){
		if(Request::instance()->isPost()){
			$user = new AdminUser();
			$group = $user->update_group_user(input('post.'));
			return $group;
		}	
	}
	// 用户组列表
	public function group(){
		$group = new AdminGroup();
		$list = $group->get_list();
		$this->assign('list',$list);
		return $this->fetch();
	}
	// 用户组添加
	public function group_add(){
		if(Request::instance()->isPost()){
			$group = new AdminGroup();
			if(input('post.')){
				$add = $group->add_group(input('post.'));
				return $add;
			}else{	
				return $this->fetch();
			}
		}	
	}
	// 用户组删除
	public function group_del(){
		if(Request::instance()->isPost()){
			$group = new AdminGroup();
			$del = $group->del_group(input('post.'));
			return $del;
		}
	}
	// 用户组修改
	public function group_edit(){
		if(Request::instance()->isPost()){
			$this->assign('id',input('post.id'));
			return $this->fetch();
		}	
	}
	// 用户组别名更变
	public function group_name(){
		if(Request::instance()->isPost()){
			$group = new AdminGroup();
			$updata = $group->update_name_group(input('post.'));
			return $updata;
		}	
	}
}

 ?>